//
//  StatusCellOriginalView.swift
//  SinaWeibo
//
//  Created by 王佳琳 on 16/2/20.
//  Copyright © 2016年 王佳琳. All rights reserved.
//

import UIKit
import SnapKit

class StatusCellOriginalView: UIView {
    
    //添加模型属性
    var status: Status? {
        didSet {
            //绑定数据
            iconImageView.sd_setImageWithURL(status?.user?.profile_url)
            nameLable.text = status?.user?.name
            mbrank_image.image = status?.user?.mbrank_image
            //TODO: 后期完善
            //            timeLabel.text = status?.created_at
            //            sourceLabel.text = status?.source
            textLable.text = status?.text
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor(white: 0.95, alpha: 1)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置UI
    private func setupUI() {
        //添加子视图
        addSubview(iconImageView)
        addSubview(nameLable)
        addSubview(mbrank_image)
        addSubview(timeLable)
        addSubview(sourceLable)
        addSubview(verified_type_image)
        addSubview(textLable)
        
        //设置约束
        iconImageView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
            make.top.equalTo(self.snp_top).offset(StatusCellMargin)
            
            //约束大小
            make.size.equalTo(CGSize(width: 40, height: 40))
        }
        nameLable.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconImageView.snp_right).offset(StatusCellMargin)
            make.top.equalTo(iconImageView.snp_top)
        }
        mbrank_image.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(nameLable.snp_right).offset(StatusCellMargin)
            make.top.equalTo(nameLable.snp_top)
        }
        timeLable.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconImageView.snp_bottom)
            make.left.equalTo(iconImageView.snp_right).offset(StatusCellMargin)
        }
        sourceLable.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLable.snp_right).offset(StatusCellMargin)
            make.top.equalTo(timeLable.snp_top)
         
        }
        verified_type_image.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(iconImageView.snp_right)
            make.bottom.equalTo(iconImageView.snp_bottom)
        }
        textLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconImageView.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(iconImageView.snp_left)
            make.right.equalTo(self.snp_right).offset(-StatusCellMargin)
        }
        //给原创微博底部添加约束
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(textLable.snp_bottom).offset(StatusCellMargin)
        }
        
        //将用户头像处理成圆角
        iconImageView.layer.cornerRadius = 20
        iconImageView.layer.masksToBounds = true
    }

    //懒加载视图
    private lazy var iconImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    //用户名称
    private lazy var nameLable: UILabel = UILabel(text: "23期同学们", fontSize: 15, textColor: themeColor)
    //微博时间
    private lazy var timeLable: UILabel = UILabel(text: "08.47", fontSize: 12, textColor: themeColor)
    //微博来源
    private lazy var sourceLable: UILabel = UILabel(text: "网路", fontSize: 12, textColor: themeColor)
    //微博等级
    private lazy var mbrank_image: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    //用户认证类型
    private lazy var verified_type_image: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    //微博正文
    private lazy var textLable: UILabel = UILabel(text: "哈哈哈哈哈  呵呵呵呵呵", fontSize: 14, textColor: UIColor.darkGrayColor(), alignment: NSTextAlignment.Left)
    
}
